<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title>GNUcode.me</title><id>https://gnucode.me/feeds/tags/OpenBSD fstab.xml</id><subtitle>Tag: OpenBSD fstab</subtitle><updated>2023-05-12T11:47:31Z</updated><link href="gnucode.me/feeds/tags/OpenBSD fstab.xml" rel="self" /><link href="gnucode.me" /><entry><title>Accidentally Deleting fstab</title><id>https://gnucode.me/accidentally-deleting-fstab.html</id><author><name>Joshua Branson</name><email>jbranso@dismail.de</email></author><updated>2023-04-05T20:00:00Z</updated><link href="https://gnucode.me/accidentally-deleting-fstab.html" rel="alternate" /><summary type="html">&lt;p&gt;The end of my previous blog post was a bit of a cliff hanger:&lt;/p&gt;&lt;p&gt;I did have a great time the next day. I was hoping to automount my usb
stick on boot. So I added this beauty to my &lt;code&gt;/etc/fstab&lt;/code&gt;.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;code&gt;sd1i /mnt/usb msdos rw 1 2&lt;/code&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;The next time I booted it threw me into a rescue shell with only &lt;code&gt;/&lt;/code&gt; mounted.&lt;/p&gt;&lt;p&gt;This is the story of how I fixed a broken fstab on OpenBSD.  The day began like
any other.  It was cold and dark as I arose to play with my new OpenBSD
computer.  It was time to reboot!  That magical moment when OpenBSD &lt;a href=&quot;https://www.openbsd.org/innovations.html&quot;&gt;relinks the
kernel at boot&lt;/a&gt;.  How cool is that?&lt;/p&gt;&lt;p&gt;My admiration for this world class operating continues to rise as it boots, and
OpenBSD proudly slaps me in the face (I did not write down the OpenBSD error
message, but this is essentially what it said):&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;mount cannot find device sd1i.  You are now in a resque shell.&lt;/p&gt;&lt;p&gt;root&amp;gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Hmmm. Well that’s a bummer. It looks like I had told OpenBSD that that usb stick
was necesary for boot. I also did not have the usb stick plugged in, and OpenBSD
needed me to write &lt;code&gt;/dev/sd1i&lt;/code&gt; not &lt;code&gt;sd1i&lt;/code&gt;. It might be a good project idea to
add &lt;a href=&quot;https://man.openbsd.org/opendev&quot;&gt;opendev&lt;/a&gt; support to OpenBSD’s mount. Any takers?&lt;/p&gt;&lt;p&gt;Anyway, to fix this, I attempted to delete that last line from &lt;code&gt;/etc/fstab&lt;/code&gt;. I
tried to type out &lt;code&gt;cd /etc/&lt;/code&gt;. Instead I got gibberish. Testing the keyboard a
bit, I noticed that the keyboard was in the qwerty layout. I use dvorak. And my
laptop keyboard physically shows a dvorak keyboard layout. It’s really hard to
type correctly on a keyboard when pressing “‘,.pyf” is “qwerty”. Well let’s
change my keyboard layout (notice that all commands below are run as the &lt;code&gt;root&lt;/code&gt;
user. The &lt;code&gt;#&lt;/code&gt; means you are running as a root user).&lt;/p&gt;&lt;p&gt;I painstakingly typed out the following command.&lt;/p&gt;&lt;pre&gt;&lt;code&gt;# wsconctl keyboard.encoding=us.dvorak&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Awesome, that is an improvement. Let’s change &lt;code&gt;/etc/fstab&lt;/code&gt;. The following
commands did not work, because the shell could not find the binary:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;code&gt;nano /etc/fstab&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;code&gt;vim /etc/fstab&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;code&gt;vi /etc/fstab&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Well that’s weird.  Is &lt;code&gt;/usr/bin&lt;/code&gt; not mounted?&lt;/p&gt;&lt;pre&gt;&lt;code&gt;# mount

/dev/sd1a on / type ffs (ro)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Oh great! I only have &lt;code&gt;/&lt;/code&gt; mounted! So my commands are limited, and &lt;code&gt;/&lt;/code&gt; is
mounted read only. So even if I find a text editor that I can use, I cannot
modify &lt;code&gt;/etc/fstab&lt;/code&gt;. How do I mount &lt;code&gt;/&lt;/code&gt; read-write? According to the irc people
who helped me out, this is how: you update the mount information based on what
&lt;code&gt;/etc/fstab&lt;/code&gt; says.&lt;/p&gt;&lt;pre&gt;&lt;code&gt;# mount -uvw /
# mount

/dev/sd1a on / type ffs (rw)&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Awesome, &lt;code&gt;fstab&lt;/code&gt; is editable! I tried to edit &lt;code&gt;/etc/fstab&lt;/code&gt; but &lt;code&gt;vi&lt;/code&gt; was not
available, probably because &lt;code&gt;vi&lt;/code&gt; is located in &lt;code&gt;/usr&lt;/code&gt;, which is not yet mounted.&lt;/p&gt;&lt;p&gt;What I should have done was &lt;code&gt;mount -U&lt;/code&gt;.  This just mounts all mount points
listed in &lt;code&gt;/etc/fstab&lt;/code&gt;.  I did not read that option in the manpage yet.  So I
decided to manually try to guess which filesytem was which.&lt;/p&gt;&lt;p&gt;Well let’s print out human read-able file sizes of my filesystem partitions and
that will give me some clue which filesystem is which. (please note that I am
intentionally removing the offsets).&lt;/p&gt;&lt;pre&gt;&lt;code&gt;# disklabel -h sd1

16 partitions:
#                size           offset  fstype [fsize bsize   cpg]
  a:             1.0G                   4.2BSD   2048 16384 12960
  b:             8.0G                     swap
  c:           931.5G                   unused
  d:             4.0G                   4.2BSD   2048 16384 12960
  e:            19.5G                   4.2BSD   2048 16384 12960
  f:            30.0G                   4.2BSD   2048 16384 12960
  g:             1.0G                   4.2BSD   2048 16384 12960
  h:            20.0G                   4.2BSD   2048 16384 12960
  i:             3.0G                   4.2BSD   2048 16384 12960
  j:             6.0G                   4.2BSD   2048 16384 12960
  k:           300.0G                   4.2BSD   4096 32768 26062&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Ok. Clearly the 300G is my &lt;code&gt;/home&lt;/code&gt;. I can mount that now.&lt;/p&gt;&lt;pre&gt;&lt;code&gt;# mount /dev/sd1k /home&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Ok. How do I mount &lt;code&gt;/usr&lt;/code&gt; so that I have text editors? I don’t really know which
partition is which. I guess I will just guess. Eventually I did correctly mount
&lt;code&gt;/usr&lt;/code&gt;, so now I should have access to some text editors! So now I could edit
&lt;code&gt;fstab&lt;/code&gt;.&lt;/p&gt;&lt;pre&gt;&lt;code&gt;# vim /etc/fstab

vim: unknown command&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Ok.  vim is not installed.  Let’s try vi.&lt;/p&gt;&lt;pre&gt;&lt;code&gt;# vi /etc/fstab

vi: unknown terminal type&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;So vi doesn’t run on the console?  That’s odd.  Ok.  Lets see what &lt;code&gt;head&lt;/code&gt;
shows me:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;# head /etc/fstab

5583d235b610c8a2.a /          ffs rw,softdep 1 1
5583d235b610c8a2.k /home      ffs rw,softdep,nodev,nosuid 1 2
5583d235b610c8a2.d /tmp       ffs rw,softdep,nodev,nosuid 1 2
5583d235b610c8a2.f /usr       ffs rw,softdep,nodev 1 2
5583d235b610c8a2.g /usr/X11R6 ffs rw,softdep,nodev 1 2
5583d235b610c8a2.h /usr/local ffs rw,wxallowed,softdep,nodev 1 2
5583d235b610c8a2.j /usr/obj   ffs rw,softdep,nodev,nosuid 1 2
5583d235b610c8a2.i /usr/src   ffs rw,softdep,nodev,nosuid 1 2
5583d235b610c8a2.e /var       ffs rw,softdep,nodev,nosuid 1 2
5583d235b610c8a2.b none swap sw&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Hey would you look at that! There is no line with &lt;code&gt;/mnt/usb&lt;/code&gt;. I should be able
to just overwrite &lt;code&gt;fstab&lt;/code&gt; with the output of &lt;code&gt;head&lt;/code&gt;. Please do NOT copy or
execute the following command:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;# head /etc/fstab &amp;gt; /etc/fstab&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I wish I had read the irc chat before I had executed the above command. In the
words of a wise sage, “the redirection happens before head runs, so you’ll just
get a blank file.” And that is exactly what happened. &lt;code&gt;/etc/fstab&lt;/code&gt; was empty.
Now how do I mount filesystem partitions in the correct locations? “Out of the
frying pan and into the fire.”&lt;/p&gt;&lt;p&gt;Some of the people on irc mentioned that &lt;code&gt;/var/backups&lt;/code&gt; should have a copy of my
&lt;code&gt;fstab&lt;/code&gt;.  Unfortunately, that backup command had not run yet.  This was a fresh
OpenBSD install afterall.&lt;/p&gt;&lt;p&gt;One of the people on the OpenBSD chat showed me this &lt;a href=&quot;https://github.com/openbsd/src/blob/master/sbin/disklabel/editor.c#L91&quot;&gt;link&lt;/a&gt;, which was super
helpful, because it shows you the default size of the various partitions that
the auto installer sets up. With that information, I was able to re-mount all my various
partitions.  Then someone on irc chat gave me this beauty of a command:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;# mount | awk '{ print $1 &amp;quot; &amp;quot; $3 &amp;quot; &amp;quot; $5 &amp;quot; rw 0 0&amp;quot;}' &amp;gt; /etc/fstab&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;That created my &lt;code&gt;fstab&lt;/code&gt; for me!  Let’s check it out!&lt;/p&gt;&lt;pre&gt;&lt;code&gt;# cat /etc/fstab

sd1.a /          ffs rw 1 1
sd1.k /home      ffs rw 1 2
sd1.d /tmp       ffs rw 1 2
sd1.f /usr       ffs rw 1 2
sd1.g /usr/X11R6 ffs rw 1 2
sd1.h /usr/local ffs rw 1 2
sd1.j /usr/obj   ffs rw 1 2
sd1.i /usr/src   ffs rw 1 2
sd1.e /var       ffs rw 1 2
sd1.b none swap sw&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Hmm, well the mount options are absent, and it is NOT using UIDs…But this
should be enough to boot into a complete system. So I rebooted. Upon reboot, I
was able to change the mount points to UIDs and copy the proper mount options
from my desktop OpenBSD. I then very quickly set up &lt;a href=&quot;https://man.openbsd.org/hotplugd&quot;&gt;hotplugd&lt;/a&gt;, which I will
explain next time.  Until then!&lt;/p&gt;</summary></entry></feed>